package SMS.service;

import SMS.mapper.BooksMapper;
import SMS.pojo.Books;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookService {
    @Autowired
    private BooksMapper booksMapper;


    public int getTotalCount() {
        return booksMapper.getTotalCount();
    }

    public List<Books> list(int currentPage, int pageSize) {
        return booksMapper.listBooks((currentPage - 1) * pageSize, pageSize);
    }

    public void updateBook(Books book) {
        booksMapper.updateByPrimaryKeySelective(book);
    }

    public void deleteBook(Long id) {
        booksMapper.deleteByPrimaryKey(id);
    }

    public int countByBookNo(String req) {
        return booksMapper.countByBookNo(req);
    }

    public int countByBookName(String req) {
        return booksMapper.countByBookName(req);
    }

    public List<Books> searchBookByName(String name, int currentPage, int pageSize) {
        return booksMapper.searchBookByName(name, (currentPage - 1) * pageSize, pageSize);
    }

    public List<Books> searchBookByNo(String no, int currentPage, int pageSize) {
        return booksMapper.searchBookByNo(no, (currentPage - 1) * pageSize, pageSize);
    }

    public void addBook(Books book) {
        booksMapper.insertSelective(book);
    }
}
